class Solution {
    int path, ret, _target;
public:
    int findTargetSumWays(vector<int>& nums, int target) {
        _target = target;
        dfs(nums, 0);
        return ret;
    }
 
    void dfs(vector<int>& nums, int pos)
    {
        if(pos ==  nums.size())
        {
            if(path == _target)
                ++ret;
            return;
        }
 
        path += nums[pos]; // 加法
        dfs(nums, pos + 1);
        path -= nums[pos]; // 回溯
 
        path -= nums[pos]; // 减法
        dfs(nums, pos + 1);
        path += nums[pos]; // 回溯
    }
};